package com.msh.frame.client.base;

import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;

public interface IConvert {

  default public <T> T convert(Class<T> clazz) {
    T t = BeanUtils.instantiateClass(clazz);
    BeanUtils.copyProperties(this, t);
    return t;
  }


  public static <ScouceT extends IConvert, TargetT extends IConvert> List<TargetT> convertList(
      List<ScouceT> s, Class<TargetT> tClazz) {
    return s.stream()
        .map(o -> o.convert(tClazz))
        .collect(Collectors.toList());
  }

}
